package com.zackeus.xupdate.factory.impl;

import android.content.Context;

import androidx.annotation.NonNull;

import com.zackeus.xupdate.XUpdate;
import com.zackeus.xupdate.constant.Error;
import com.zackeus.xupdate.entity.UpdateError;
import com.zackeus.xupdate.factory.IUpdateInstaller;
import com.zackeus.xupdate.utils.ApkInstallUtils;

import java.io.File;

/**
 * 默认的apk安装器
 * @name: DefaultInstallListener
 * @author: zz
 * @date: 2022/11/21
 */
public class DefaultIUpdateInstaller implements IUpdateInstaller {

    @Override
    public boolean startInstall(@NonNull Context context, @NonNull File apkFile) {
        try {
            return ApkInstallUtils.install(context, apkFile);
        } catch (Exception e) {
            XUpdate.with().onUpdateError(new UpdateError(Error.INSTALL_FAILED, "An error occurred while install apk:" + e.getMessage()));
            return Boolean.FALSE;
        }
    }
}
